package com.api.oa.mapper;

import com.api.oa.model.entity.YQVideo;
import com.api.oa.model.vo.OaNoticeVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface YQVideoMapper {

    @Insert("insert into  yq_video  (" +
            "videoRes," +
            "videoLen," +
            "videoScore," +
            "insCode," +
            "videoFrom," +
            "videoTitle," +
            "createdAt" +
            ") " +
            "values " +
            "(" +
            "#{entity.videoRes}," +
            "#{entity.videoLen}," +
            "#{entity.videoScore}," +
            "#{entity.insCode}," +
            "#{entity.videoFrom}," +
            "#{entity.videoTitle}," +
            "#{entity.createdAt}" +
            ")")
    @Options(useGeneratedKeys = true, keyProperty = "videoId", keyColumn = "id")
    Integer insert(@Param("entity") YQVideo entity);


    @Update("update  yq_video  set " +
            "videoRes = #{entity.videoRes}," +
            "videoLen = #{entity.videoLen}," +
            "videoScore = #{entity.videoScore}," +
            "insCode = #{entity.insCode}," +
            "videoFrom = #{entity.videoFrom}," +
            "videoTitle = #{entity.videoTitle}," +
            "createdAt = #{entity.createdAt}" +
            " where videoId = #{entity.videoId}")
    Integer update(@Param("entity") YQVideo entity);


    @Delete("delete from yq_video where videoId=#{id}")
    void delete(@Param("id") Long id);


    @Select("<script> select yq_video.*,yq_ins.insName from  yq_video left join yq_ins on yq_ins.insCode = yq_video.insCode where 1=1" +
            "<if test='insCode!=null and insCode!=\"\"'> and yq_video.insCode = #{insCode}</if> " +
            "<if test='keyWord!=null and keyWord!=\"\"'> and concat(ifnull(yq_video.videoTitle,''),ifnull(yq_video.videoFrom,'')) like concat('%', #{keyWord},'%')</if> " +
            "</script> ")
    List<YQVideo> list(@Param("insCode") String insCode, @Param("keyWord") String keyWord);


    @Select("select * from  yq_video  where videoId = #{id} limit 1")
    YQVideo findOne(@Param("id") Long id);

}

